package cn.ac.cintcm.synonymous;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class ResultFilterTerms extends ResultTerms {
    private static Logger logger = Logger.getLogger(ResultFilterTerms.class);
    
    public ResultFilterTerms(ResultTerms rt) {
        copyField(rt);
    }

    private void copyField(ResultTerms rt) {
        this.data = rt.getData();
        this.terms = rt.terms;
    }
    
    public void filter(String type) {
        if (type != null) {
            List<String[]> newData = new ArrayList<String[]>();
            newData.add(new String[3]);
            for (String[] r : data) {
                if (r != null && r[Term.ATTRIBUTE_TYPE] != null && r[Term.ATTRIBUTE_TYPE].equals(type)) {
                    newData.add(r);
                }
            }
            data = newData.toArray(new String[0][0]);
        }
    }
    
    public void filterTerm(String term) {
        if (term != null) {
            List<String[]> newData = new ArrayList<String[]>();
            newData.add(new String[3]);
            for (String[] r : data) {
                if (r != null && r[Term.ATTRIBUTE_NAME] != null && 
                        r[Term.ATTRIBUTE_NAME].contains(term)) {
                    newData.add(r);
                }
            }
            data = newData.toArray(new String[0][0]);
        }
    }
 }
